package com.apartmentManage.service.impl;

import com.apartmentManage.Dao.ApartmentTutorDao;
import com.apartmentManage.entity.ApartmentTutor;
import com.apartmentManage.service.ApartmentTutorService;
import com.apartmentManage.until.IDRandom;
import com.apartmentManage.until.StringUntil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApartmentTutorServiceImpl implements ApartmentTutorService {

    @Autowired
    private ApartmentTutorDao apartmentTutorDao;

    @Override
    public List<ApartmentTutor> getAll() {
        return apartmentTutorDao.getAll();
    }

    @Override
    public List<ApartmentTutor> getByRequirement(ApartmentTutor apartmentTutor) {
        return apartmentTutorDao.getByRequirement(apartmentTutor);
    }

    @Override
    public ApartmentTutor getByAccountName(ApartmentTutor apartmentTutor) {
        ApartmentTutor result = apartmentTutorDao.getByAccountName(apartmentTutor);
        return result;
    }

    @Override
    public ApartmentTutor getByNo(String no) {
        return apartmentTutorDao.getByNo(no);
    }

    @Override
    public boolean save(ApartmentTutor apartmentTutor) {
        if (StringUntil.IsBlank(apartmentTutor.getTname())
                || StringUntil.IsBlank(apartmentTutor.getAccountName())
                || StringUntil.IsBlank(apartmentTutor.getPassword())
                || StringUntil.IsBlank(apartmentTutor.getTelephone()))
            return false;
        ApartmentTutor result = getByAccountName(apartmentTutor);
        if (result!=null)
            return false;
//        产生随机Id
        apartmentTutor.setTno(IDRandom.getId(apartmentTutorDao.getAllNo()));
        return apartmentTutorDao.save(apartmentTutor)>0;
    }

    @Override
    public boolean update(ApartmentTutor apartmentTutor) {
        return apartmentTutorDao.update(apartmentTutor)>0;
    }

    @Override
    public boolean delete(String no) {
        return apartmentTutorDao.delete(no)>0;
    }
}
